/**
 * 
 */
package com.iss.card.view.account.shake;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;

/**
 * @author dtdh
 * 
 */
public class ViewTranslateAnimation {
	private final static String TAG = ViewTranslateAnimation.class
			.getSimpleName();
	private View mViewBeforeAnimation;
	private View mViewAfterAnimation;

	public ViewTranslateAnimation(Context ct, View viewBeforeAnimation,
			View viewAfterAnimation) {
		mViewBeforeAnimation = viewBeforeAnimation;
		mViewAfterAnimation = viewAfterAnimation;
	}

	public void startTranslateAnimation() {
		applyRotation(0, 90);
	}

	private void applyRotation(float start, float end) {
		// Find the center of the container
		final float centerX = mViewBeforeAnimation.getWidth() / 2.0f;
		final float centerY = mViewBeforeAnimation.getHeight() / 2.0f;
		final Rotate3d rotation = new Rotate3d(start, end, centerX, centerY,
				310.0f, false);
		rotation.setDuration(1000);
		rotation.setFillAfter(false);
		rotation.setInterpolator(new AccelerateInterpolator());
		rotation.setAnimationListener(new Animation.AnimationListener() {

			@Override
			public void onAnimationStart(Animation animation) {
				Log.d(TAG, "onAnimationStart");
			}

			@Override
			public void onAnimationEnd(Animation animation) {
				Log.d(TAG, "onAnimationEnd");
				mViewBeforeAnimation.setVisibility(View.INVISIBLE);
				mViewAfterAnimation.setVisibility(View.VISIBLE);
			}

			@Override
			public void onAnimationRepeat(Animation animation) {
				Log.d(TAG, "onAnimationRepeat");
			}
		});
		mViewBeforeAnimation.startAnimation(rotation);
	}

}
